Pain algorithm